import request from '@/utils/request';
import moment from 'moment'
import {getEW} from "@/utils/utils";

export async function query({...resetParams}) {
  return request(`/meter_analysis`,{
    method:'GET',
    params:{
      ...resetParams,
      order_direction:'desc',
      order_column:'consumption',
      company_ids:getEW(resetParams.company_ids),
    }
  });
}

export async function queryResources({...resetParams}) {
  return request(`/meter_historical_data`,{
    method:'GET',
    params:{
      meter_id:resetParams.meter_id,
      start_date:moment(moment().subtract(30, 'days').calendar()).format('YYYY-MM-DD'),
      end_date:moment().format('YYYY-MM-DD'),
    }
  });
}

export async function queryLogs({...resetParams}) {
  return request(`/devices/${resetParams.id}/online_logs`,{
    method:'GET',
    params:{
      ...resetParams
    }
  });
}

export async function remove({id}) {
  return request(`/devices/${id}`, {
    method: 'DELETE',
  });
}


export async function add(restParams) {
  return request(`/devices`, {
    method: 'POST',
    data: {
      ...restParams,
    },
  });
}

export async function edit({id,...restParams}) {
  return request(`/devices/${id}`, {
    method: 'PATCH',
    data: {
      ...restParams,
    },
  });
}

